package 最长递增子序列问题;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class 马戏团最佳解决 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int high[] = new int[n];
			int weight[] = new int[n];
			for (int i = 0; i < n; i++) {
				sc.nextInt();
				high[i] = sc.nextInt();
				weight[i] = sc.nextInt();
			}
			System.out.println(getLHnum(high, weight, n));
		}
		sc.close();
	}

	public static int getLHnum(int high[], int weight[], int n) {
		ArrayList<Node> list = new ArrayList<Node>();
		for (int i = 0; i < n; i++) {
			list.add(new Node(high[i], weight[i], i + 1));
		}
		Collections.sort(list, new NodeComparator());
		int[] a = new int[list.size()];
		for (int i = 0; i < list.size(); i++) {
			a[i] = list.get(i).weight;
		}
		int res = getLong(a, a.length);
		return res;
	}

	public static int getLong(int a[], int n) {
		int dp[] = new int[n];
		int r = 0;
		for (int i = 0; i < n; i++) {
			dp[i] = 1;
			for (int j = 0; j < i; j++)
				if (a[j] >= a[i])
					dp[i] = Math.max(dp[i], dp[j] + 1);
			r = r < dp[i] ? dp[i] : r;
		}
		return r;
	}

	public static class NodeComparator implements Comparator<Node> {

		@Override
		public int compare(Node o1, Node o2) {
			if (o1.high != o2.high) {
				return o1.high > o2.high ? -1 : 1;
			} else if (o1.weight != o2.weight) {
				return o1.weight > o2.weight ? 1 : -1;
			} else {
				return (o1.index > o2.index) ? 1 : -1;
			}
		}
	}

	public static class Node {
		int high;
		int weight;
		int index;

		public Node(int high, int weight, int index) {
			this.weight = weight;
			this.high = high;
			this.index = index;
		}
	}
}